<?
require_once('unicode.php');

function print_entry($key,$entry)
{
  if($start >= count($entry)) return;

  $line = sprintf("\"%s\",",$key);
  for($i=0;$i<count($entry);$i++) {
    $value = $entry[$i];
    $line .= sprintf("\"%s\",",$value);
  }
  $line = rtrim($line,',');
  printf("%s\n",$line);
}


if(count($argv) < 2) return;

$fp = fopen($argv[1],'r');

$entries = array();
while($line = fgets($fp)) {
  $line = rtrim($line,"\n");
  $pos = strpos($line,' ');
  $txt = substr($line,0,$pos);
  $data = substr($line,$pos+1);

  if(key_exists($txt,$entries)) {
    $entry = $entries[$txt];
    $entry[] = $data;
    $entries[$txt] = $entry;
  }
  else {
    $entry = array();
    $entry[] = $data;
    $entries[$txt] = $entry;
  }
}
fclose($fp);

foreach($entries as $key => $entry) {
  print_entry($key,$entry);
}


?>
